package Hello;

import com.mongodb.*;
import java.net.UnknownHostException;

public class Youtube {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
   	      System.out.println("Hello World");

		try
		{
	         MongoClient mongo = new MongoClient( "localhost" , 27017 );
	         DB db = mongo.getDB("Youtube");//create database if it does not exist
	         
	         DBCollection collection = db.getCollection("OurCollections");
	         
	         
	      // create a document to store values
	            BasicDBObject document = new BasicDBObject();
	            document.put("id", 1);
	            document.put("msg", "Hello");
	 
	            // save it into collection named "MyCollection"
	            collection.insert(document);
                 // search query
	            BasicDBObject searchQuery = new BasicDBObject();
	            searchQuery.put("id", 1001);
	 
	            // query it
	            DBCursor cursor = collection.find(searchQuery);
	 
	            // loop over the cursor and display the retrieved result
	            while (cursor.hasNext()) {
	                System.out.println(cursor.next());
	            }
	 
	            System.out.println("Done");
		}
	
		catch(Exception e)
		{
			System.out.println("Something is worng: "+e);
		}
         


	}

}
